﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Messaging.Listener;
using Engine.Messaging.Messages;
using Microsoft.Xna.Framework;

namespace Engine.Game.Cameras
{
    public class FreeflyCamera : Camera, IMessageListener<TextMessage>
    {
        #region Properties
        public float MovingSpeed { get; set; }
        public Vector3 MoveDirection { get; set; }
        #endregion // Properties


        #region Constructors
        public FreeflyCamera(float aspectRatio) : base(aspectRatio)
        {
            Engine.TheEngine.MessageSystem.Subscribe(this);
            MovingSpeed = 5.0f;
        }
        #endregion // Constructors


        #region Methods
        public void Recieve(object sender, TextMessage m)
        {
            if (m.Text.Equals("move_forward"))
                this.MoveDirection = Vector3.Forward;
            if (m.Text.Equals("move_backward"))
                this.MoveDirection += Vector3.Backward;
            if (m.Text.Equals("move_left"))
                this.MoveDirection += Vector3.Left;
            if (m.Text.Equals("move_right"))
                this.MoveDirection += Vector3.Right;
        }

        protected override void UpdateCamera(GameTime gameTime)
        {
            this.Position += MoveDirection * MovingSpeed;
        }



        protected override void Shutdown()
        {
            Engine.TheEngine.MessageSystem.Unsubscribe(this);
        }
        #endregion // Methods
    }
}
